import { defineStore } from "pinia";
import { ref } from "vue";
import { userLoginAPI } from "@/apis/User";

export const useUserStore = defineStore(
  "user",
  () => {
    const useInfo = ref({});

    const getUseInfo = async ({ student_id, password }) => {
      try {
        const res = await userLoginAPI({ student_id, password });
        useInfo.value = res.data;
      } catch (err) {
        console.log("API登录错误", err);
        //进一步抛出错误
        throw err;
      }
    };

    const clearUserInfo = () => {
      useInfo.value = {};
    };

    return {
      getUseInfo,
      useInfo,
      clearUserInfo,
    };
  },
  {
    persist: true,
  },
);
